<html class="bg-white ">
<head>
	<title>代码生成</title>
	<link rel="stylesheet" type="text/css" href="http://test.arp.cn/css/app.css">
	<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css">

</head>
<style type="text/css">
	*{
		box-sizing:border-box;
	}
</style>
<body class="bg-white padder-sm padder-v-sm m-n">
	<div class="hbox ">
		<div class="col b-a b-2x r-3x v-top" id='demo' style="background: #F0F0F0;width:500px;overflow=auto">
				<textarea  class="w-full h-full no-border b-b  m-b-sm" id='demo_content' placeholder='请输入json如左侧所示:'></textarea>
		</div>
		<div class="col w-xxs"></div>
		<div class="col b-a b-2x r-3x v-top">
			<textarea class="w-full no-border b-b m-b-sm" style="height:80%" id='content' placeholder='请输入json如左侧所示:'></textarea>
			<a 
			class="btn padder-v-xs padder-sm m-l-sm
			btn-primary" id='btn' >提交并生成代码</a> 
		</div>
	</div>
</body>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js"></script>
<script type="text/javascript">
$('#demo_content').val(`
//entity示例 form字段类型date、text、staff
{
	"name":"tPerson",
	"tableName":"PMO_T_PERSON",
	"comment":"人员",
	"author":"dapaer",
	"version":"v1.0.0",
	"module":"pmo",
	"column":{
		"NAME":{
			"type":"String",
			"comment":"姓名"
		},
		"AGE":{
			"type":"Integer",
			"comment":"年龄"
		},
		"MY_DATE":{
			"type":"Date",
			"comment":"日期"
		},
		"STAFF_ID":{
			"type":"String",
			"comment":"人员Id",
			"format":"SQLKEY:HR_STAFF_INFO"
		}
	},
	"pages":[{
		"comment":"编辑页面",
		"name":"create",
		"type":"FORM",
		"columns":[
			{
				"name":"NAME",
				"type":"text",
				"require":true,
				"maxlength":200
			},{
				"name":"AGE",
				"type":"text",
				"require":true,
				"maxlength":200
			},{
				"name":"MY_DATE",
				"type":"date",
				"require":true,
				"maxlength":200
			},{
				"name":"STAFF_ID",
				"type":"staff"
			}
		],
		"form_btns":[
			{
				"name":"保存",
				"type":"SAVE",
				"isVali":true
			},
			{
				"name":"暂存",
				"type":"TEMP",
				"isVali":true
			},
			{
				"name":"删除",
				"type":"DELETE"
			}
		]

	},
	{
		"comment":"列表页面",
		"name":"list",
		"type":"LIST",
		"searchKey":"NAME",
		"columns":[
			{
				"name":"NAME"
			},{
				"name":"AGE"
			},{
				"name":"MY_DATE"
			},{
				"name":"STAFF_ID"
			}
		],
		"title_bar_btn":[
			{
				"name":"新建",
				"type":"TO_PAGE",
				"pageName":"create"
			}
		],
		"listLink":{
			"type":"TO_PAGE",
			"pageName":"create",
			"params":["ID"]	
		},
		"tempLink":{
			"type":"TO_PAGE",
			"pageName":"create",
			"params":["ID"]	
		},
		"pauthLink":{
			"type":"TO_PAGE",
			"pageName":"detail",
			"params":["ID"]	
		}
	},
	{
		"comment":"详情页面",
		"name":"detail",
		"type":"DETAIL",
		"columns":[
			{
				"name":"NAME"
			},{
				"name":"AGE"
			},{
				"name":"MY_DATE"
			},{
				"name":"STAFF_ID"
			}
		]

	},
	{
		"comment":"审批页面",
		"name":"appr",
		"type":"APPR",
		"columns":[
			{
				"name":"NAME"
			},{
				"name":"AGE"
			},{
				"name":"MY_DATE"
			},{
				"name":"STAFF_ID"
			}
		]

	}],
	"hasWorkflow":true,
	"workflowInfo":{
		"apprLisColumns":[
			{
				"name":"NAME"
			},{
				"name":"AGE"
			},{
				"name":"MY_DATE"
			},{
				"name":"STAFF_ID"
			}
		],
		"apprPageName":"appr"
	}
}
	
	
	
	`)
hljs.initHighlightingOnLoad();
$(document).ready(function() {
  $('pre code').each(function(i, block) {
    hljs.highlightBlock(block);
  });
});

var changeEnSymbol = function(str){ 
    str=str.replace(/，/ig,','); 
    str=str.replace(/“/ig,'"');  
    str=str.replace(/”/ig,'"');  
    str=str.replace(/：/ig,':');  
    str=str.replace(/{/ig,'{'); 
    str=str.replace(/}/ig,'}');
    str=str.replace(/【/ig,'[');
    str=str.replace(/】/ig,']');
    return str; 
} 
var getZip = function(){
	try{
		$.post('/getZip',{entity:JSON.stringify(JSON.parse(changeEnSymbol($('#content').val()).replace(/\s*/g,'')))},function(data){
			window.location.href = data;
		})
	}catch(e){
		alert('请输入正确json!!!');
	}
}
function downloadFile(fileName, content) {
    var aLink = document.createElement('a');
    var blob = content;
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent("click", false, false);
    aLink.download = fileName;
    aLink.href = URL.createObjectURL(blob);
    aLink.dispatchEvent(evt);
    $(aLink).click();
}
$('#btn').click(getZip);
 </script>


</html>